package com.gxg.config.yamlSources;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;

/**
 * Created by guxiaoguang on 2018/5/8.
 */
@Configuration
public class PropertySources {
    // 加载YML格式自定义配置文件
    @Bean
    public PropertySourcesPlaceholderConfigurer properties() {
        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
        YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
        //yaml.setResources(new FileSystemResource("conf/redis.yml"));//File引入
        yaml.setResources(new ClassPathResource("conf/redis.yml"));//class引入
        configurer.setProperties(yaml.getObject());
        return configurer;
    }
}
